package com.ksd.web.controller.system;


import com.ksd.common.core.controller.BaseController;
import com.ksd.common.core.domain.AjaxResult;
import com.ksd.common.utils.DateUtils;
import com.ksd.system.domain.SysChannel;
import com.ksd.system.domain.SysMovie;
import com.ksd.system.service.*;
import com.ksd.web.controller.domain.IndexResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @Author y.wu
 * @Create 2023/11/9 下午 3:27
 */
@RestController
@RequestMapping("/system/firstIndex")
public class FirstIndexController extends BaseController
{

    @Autowired
    private ISysChannelService sysChannelService;

    @Autowired
    private ISysFreqService sysFreqService;
    @Autowired
    private ISysMovieService sysMovieService;
    @Autowired
    private ISysMusicDataService sysMusicDataService;

    @GetMapping("/getIndexInfo")
    public AjaxResult getIndexInfo()
    {
        //首页查询所有数据

        SysChannel sysChannel = new SysChannel();
        sysChannel.setBoardId(1L);
        List<SysChannel> sysChannelOne = sysChannelService.selectSysChannelList(sysChannel, "sys_channel_one");
        sysChannel.setBoardId(2L);
        List<SysChannel> sysChannelTwice = sysChannelService.selectSysChannelList(sysChannel, "sys_channel_twice");

        System.out.println("直播板卡1频道数:"+sysChannelOne.size());
        System.out.println("直播板卡2频道数:"+sysChannelTwice.size());

        SysMovie sysMovie = new SysMovie();
        List<SysMovie> movieList = sysMovieService.selectSysMovieList(sysMovie);


        String s = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD);
        System.out.println("s:"+s);

        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();

        // 定义日期时间格式化模式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD);

        // 格式化当前时间
        String formattedCurrentTime = currentTime.format(formatter);
        System.out.println("当前时间: " + formattedCurrentTime);

        LocalDateTime previousDayTime  = currentTime.minusDays(1);

        // 将当前时间往后移一天
        LocalDateTime nextDayTime = currentTime.plusDays(1);

        // 格式化往后移一天的时间
        String formattedNextDayTime = nextDayTime.format(formatter);
        System.out.println("往后移一天的时间: " + formattedNextDayTime);
        Map<String,Object> params = new HashMap<>();
        params.put("beginTime",formattedCurrentTime);
        params.put("endTime",formattedNextDayTime);
        sysMovie.setParams(params);
        List<SysMovie> movieListDay = sysMovieService.selectSysMovieList(sysMovie);

        // 统计直播板卡1、直播板卡2频道数量
        IndexResultData indexResultData = new IndexResultData();
        indexResultData.setChannleCount1(sysChannelOne.size());
        indexResultData.setChannleCount2(sysChannelTwice.size());
        indexResultData.setContentCount(movieList.size());
        indexResultData.setContentDayCount(movieListDay.size());

        return success(indexResultData);
    }





    public static void main(String[] args) {

        ArrayList<String> xData = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        int k = 6;
        for (int i = 0; i <= k; i++) {
            int j = i - k;
            calendar.setTime(new Date());
            calendar.add(Calendar.DAY_OF_YEAR, j);
            Date nextDay = calendar.getTime();
            String s = DateUtils.dateTime(nextDay);
            System.out.println("s: "+s);
            xData.add(s);
        }

    }

    public ArrayList<String> getXData(int timeframe){
        ArrayList<String> xData = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        int k = timeframe - 1;
        for (int i = 0; i <= k; i++) {
            int j = i - k;
            calendar.setTime(new Date());
            calendar.add(Calendar.DAY_OF_YEAR, j);
            Date nextDay = calendar.getTime();
            String s = DateUtils.dateTime(nextDay);
            xData.add(s);
        }
        return xData;
    }

}

